<?php
/**
 * Точка входа в проект
 *
 * @since 30.10.11
 * @author Akulov Denis <akulov.d.g@gmail.com>
 */

error_reporting(E_ALL);
session_start();

xhprof_enable();

require_once '../../../config.php';
require_once '../../../autoloader.php';

$config = new K_Config('config.php');
$gc = new K_GlobalContext();

$container = new K_Container_OnlyRead(array(
    'CONFIG'         => $config,
    'global_context' => $gc,
    'POST'           => new K_Container_OnlyRead($_POST),
    'GET'            => new K_Container_OnlyRead($_GET),
    'SERVER'         => new K_Container_OnlyRead($_SERVER),
    'SESSION'        => new K_Container($_SESSION),
    'factory_models' => new K_MVC_Model_Factory($config, $gc),
    'logger'         => new K_Logger(),
));

$objBuilder = new K_Builder($container);
$htmlPage = $objBuilder->build();


// print 'Hello world!!';

// $htmlPage = '<pre><!-- PROFILER --></pre>';

$xhprof_data = xhprof_disable();

include_once "xhprof_lib/utils/xhprof_lib.php";
include_once "xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_test");
$profiler = "<a href=\"http://profiler/index.php?run=$run_id&source=xhprof_test\">Profiler</a>";
print str_replace('<!-- PROFILER -->', $profiler, $htmlPage);

$_SESSION = $container->get('SESSION')->getAsArray();